// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-02-01 // using System.Collections.Generic; using System.Linq; using LargoCommon.Abstract; namespace LargoCommon.Music { /// /// Element Master /// public class ElementMaster { #region Constructors /// /// Initializes a new instance of the class. /// /// The given list. public ElementMaster(IEnumerable givenList) { this.List = givenList; } #endregion #region Public properties /// /// Gets or sets the list. /// /// /// The list. /// public IEnumerable List { get; set; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { return "Element Master"; } #endregion #region Public methods /// /// Sets the random rhythm. /// /// The rhythmic structures. public void SetRandomRhythm(IList rhythmicStructures) { var cnt = rhythmicStructures.Count; foreach (var element1 in this.List) { if (element1 == null) { continue; } var i = 0; RhythmicStructure rstruct; while (true) { var idx = MathSupport.RandomNatural(cnt); rstruct = rhythmicStructures[idx]; if (rstruct.Level > 0 || i > 10) { break; } i++; } element1.Status.RhythmicStructure = rstruct; } } /// /// Reorders the line rhythmic. /// public void ReorderRhythmic() { foreach (var element1 in this.List) { if (element1?.Status.RhythmicStructure == null) { continue; } foreach (var element2 in this.List) { if (element2?.Status.RhythmicStructure == null || element2.Bar.BarNumber <= element1.Bar.BarNumber) { continue; } //// Random Effect //// if (MathSupport.RandomNatural(10) >= 3) { //// continue; //// } var rhythmicStructure = element2.Status.RhythmicStructure; element2.Status.RhythmicStructure = element1.Status.RhythmicStructure; element1.Status.RhythmicStructure = rhythmicStructure; } } } /// /// Reorders the line melodic. /// public void ReorderMelodic() { foreach (var element1 in this.List) { if (element1?.Status.RhythmicStructure == null) { continue; } var element1C = element1; foreach (var element2 in this.List.Where(element2 => element2.Status.RhythmicStructure != null && element2.Bar.BarNumber > element1C.Bar.BarNumber).Where(element2 => MathSupport.RandomNatural(10) < 3)) { element1.SwapMelodicWith(element2); } } } #endregion /// /// Converts to melodic. /// /// The given channel. public void ConvertToMelodic(MidiChannel givenChannel) { foreach (var elem in this.List) { elem.Status.LineType = MusicalLineType.Melodic; elem.Status.Instrument = new MusicalInstrument(MidiMelodicInstrument.NylonAcousticGuitar); //// AcousticGrandPiano elem.Status.MelodicShape = MelodicShape.Scales; elem.Status.Octave = MusicalOctave.OneLine; elem.Status.MelodicGenus = MelodicGenus.Melodic; elem.Status.MelodicFunction = MelodicFunction.HarmonicMotion; //// elem.Status.Channel = givenChannel; elem.Status.LocalPurpose = LinePurpose.Composed; elem.Tones = new MusicalStrikeCollection(); } } /// /// Converts to rhythmic. /// /// The given channel. public void ConvertToRhythmic(MidiChannel givenChannel) { foreach (var elem in this.List) { elem.Status.LineType = MusicalLineType.Rhythmic; elem.Status.Instrument = new MusicalInstrument(MidiRhythmicInstrument.AcousticSnare); elem.Status.MelodicShape = MelodicShape.None; elem.Status.Octave = MusicalOctave.None; elem.Status.MelodicGenus = MelodicGenus.None; elem.Status.MelodicFunction = MelodicFunction.None; //// elem.Status.Channel = givenChannel; elem.Status.LocalPurpose = LinePurpose.Composed; elem.Tones = new MusicalStrikeCollection(); } } /// /// Eliminates the melodic dependencies. /// public void EliminateMelodicDependencies() { foreach (var element in this.List) { if (element.Status.OriginalMelodicPoint.IsDefined) { element.Status.LocalPurpose = LinePurpose.Mute; element.Status.LineType = MusicalLineType.None; element.Tones = new MusicalStrikeCollection(); } } } /// /// Eliminates the rhythmic dependencies. /// public void EliminateRhythmicDependencies() { foreach (var element in this.List) { if (element.Status.OriginalRhythmicPoint.IsDefined) { element.Status.LocalPurpose = LinePurpose.Mute; element.Status.LineType = MusicalLineType.None; element.Tones = new MusicalStrikeCollection(); } } } /// /// Haves any purpose. /// /// /// Returns value. /// public bool HaveAnyPurpose() { bool isEmpty = true; foreach (var element in this.List) { if (element.Status.LocalPurpose == LinePurpose.Mute || element.Status.LocalPurpose == LinePurpose.None) { continue; } isEmpty = false; } return !isEmpty; } } }